/*
@hehung
2023-2-8
转载请注明出处，版权由@hehung所有
email: 1398660197@qq.com
wechat: hehung95
*/

#include "hal_data.h"
#include "app_led.h"
#include "app_key.h"
#include "app_bl.h"


#define TASK_PERIOD_1000MS              (500U)
#define TASK_PERIOD_500MS               (250U)
#define TASK_PERIOD_100MS               (50U)
#define TASK_PERIOD_10MS                (5U)
#define TASK_PERIOD_2MS                 (1U)



static uint32_t timer_10ms_cnt = 0U;
static uint32_t timer_100ms_cnt = 0U;
static uint32_t timer_1000ms_cnt = 0U;


static void timer1_task_1000ms(void);
static void timer1_task_500ms(void);
static void timer1_task_100ms(void);
static void timer1_task_10ms(void);
static void timer1_task_2ms(void);


extern uint8_t Bl_Start_Flag;

static void timer1_task_1000ms(void)
{
	Led_Toggle(LED_3);
}

static void timer1_task_500ms(void)
{

}

static void timer1_task_100ms(void)
{
	if (BL_CODE_DOWNLOAD_START == Bl_GetDownloadStatus())
	{
		Led_Toggle(LED_2);
	}
}

static void timer1_task_10ms(void)
{
	Key_RunningEntry();
}

static void timer1_task_2ms(void)
{
	
}

static uint16_t iii = 0;
void timer0_1ms_callback(timer_callback_args_t *p_args)
{
	FSP_PARAMETER_NOT_USED(p_args);

	Bl_TimeoutLgc();
	
	if (Bl_Start_Flag == 1)
	{
		if (iii > 100)
		{
			iii = 0;
			Led_Toggle(LED_1);
		}	
		else
		{
			iii++;
		}
	}
}

void timer1_2ms_callback(timer_callback_args_t *p_args)
{
	FSP_PARAMETER_NOT_USED(p_args);
	
	timer_1000ms_cnt ++;
	timer_100ms_cnt ++;
	timer_10ms_cnt ++;
}

void sci3_i2c_master_callback(i2c_master_callback_args_t *p_args)
{
	(void)p_args;
}

void Timer1_TaskRunning(void)
{
	if (timer_10ms_cnt >= TASK_PERIOD_10MS)
	{
		timer1_task_10ms();
		timer_10ms_cnt = 0U;
	}

	if (timer_100ms_cnt >= TASK_PERIOD_100MS)
	{
		timer1_task_100ms();
		timer_100ms_cnt = 0U;		
	}
	
	if (timer_1000ms_cnt >= TASK_PERIOD_1000MS)
	{
		timer1_task_1000ms();
		timer_1000ms_cnt = 0U;
	}
}
